package com.example.carrierapp.ui.person;

import android.app.Activity;
import android.content.Context;

import com.example.carrierapp.base.BasePresenter;
import com.example.carrierapp.bean.home.PersonalInfoBean;
import com.example.carrierapp.bean.home.SearchCarBean;
import com.example.carrierapp.net.ApiMiddleHelper;
import com.example.carrierapp.net.listener.DataCallBackListener;
import com.example.carrierapp.util.LogUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

import io.reactivex.Flowable;

/**
 * Created by Administrator on 2017/1/4.
 */
public class PersonCenterPrenter extends BasePresenter<PersonCenterContract.View> implements PersonCenterContract.Presenter {
    private SearchCarBean searchCarBean;
    private Context mContext;
    public PersonCenterPrenter(Activity context) {
        mContext=context;
    }

    @Override
    public void start() {

    }

    @Override
    public void getUserInfo() {
        Flowable<JsonObject> searchFilter = apiStrores.getUserInfo();
        ApiMiddleHelper.getInstance().toNetIo2Main(mContext,searchFilter, new DataCallBackListener() {
            @Override
            public void onSuccess(String json) {
                LogUtil.d("getUserInfo-onSuccess-" + json);
                try {
                    PersonalInfoBean dispatchToatBean = new Gson().fromJson(json, new TypeToken<PersonalInfoBean>() {
                    }.getType());
                    if (getView() != null) {
                    getView().getUserInfoSuccess(dispatchToatBean);

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    if (getView() != null) {
                    getView().getUserInfoField("数据获取失败");

                    }
                }
            }

            @Override
            public void onFailure(String msg) {
                LogUtil.d("getUserInfo-onFailure-" + msg);
                if (getView() != null) {
                getView().getUserInfoField( msg);

                }
            }
        });
    }
}
